﻿namespace FFF.Test.Application.AppServices.PublicService.Ueditor
{
    using System;
    using System.Collections.Generic;
    using System.IdentityModel.Tokens.Jwt;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Security.Claims;
    using System.Text;
    using System.Threading.Tasks;
    using Abp.Application.Services;
    using Abp.Application.Services.Dto;
    using Abp.Auditing;
    using Abp.Dependency;
    using Abp.EntityFrameworkCore;
    using Abp.Runtime.Security;
    using Abp.Web.Models;
    using AutoMapper.Configuration;
    using Microsoft.AspNetCore.Authentication.JwtBearer;
    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Extensions.Configuration;
    using Microsoft.IdentityModel.Tokens;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Serialization;
    using FFF.Test.Application.AppServices;
    using FFF.Test.DataAccess.Framework;
    using FFF.Test.Util.Web;
    using UEditorNetCore;
    using Ydm.Extensions;
    using Microsoft.AspNetCore.Authorization;

    /// <summary>
    /// Ueditor服务
    /// </summary>
    [YdmApiVersionAttribute(Version = "My")]
    public class UeditorAppService : YdmAbpAppServiceBase, IUeditorAppService
    {
        private readonly IDbContextProvider<MyDbContext> _dbContextProvider;

        /// <summary>
        /// 依赖注入容器
        /// </summary>
        public IIocResolver IocResolver { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="UeditorAppService"/> class.
        /// toke构造方法初始化配置对象
        /// </summary>
        /// <param name="dbContextProvider">dbContextProvider</param>
        public UeditorAppService(IDbContextProvider<MyDbContext> dbContextProvider)
        {
            this._dbContextProvider = dbContextProvider;
        }

        /// <summary>
        /// 处理Ueditor请求
        /// </summary>
        [HttpGet]
        [HttpPost]
        [AllowAnonymous]
        [WrapResult(WrapOnSuccess = false, WrapOnError = false)]
        public void ProcessRequest()
        {
            HttpContext context = this.IocResolver.Resolve<IHttpContextAccessor>().HttpContext;
            UEditorService service = this.IocResolver.Resolve<UEditorService>();
            Config.WebRootPath = Server.MapPath(@"~\lib\YdmJUI\static\plugins\ueditorAPP");
            service.DoAction(context);
        }
    }
}